struct VertexBufferInput
{
	uint uControlPoint								: CONTROLPOINTID; 
	float4 f4Normal									: NORMAL;
	float2 f2Tex									: TEXCOORD0;
};

struct VertexBufferOutput
{
	float2 f2Tex									: TEXCOORD0;
	float4 f4Normal									: NORMAL;
	float4 f4ViewDirection							: TEXCOORD1;
	float4 f4LightDirection							: TEXCOORD2;
	float4 f4Position								: SV_POSITION;
};

struct ControlPoint
{
	float4 f4ControlPoint;
};

cbuffer PerModel									: register (cb0)
{
	row_major float4x4 g_f4x4World;
	row_major float4x4 g_f4x4View;
	row_major float4x4 g_f4x4Proj;
	float4 g_f4CameraPositionWorld;
};

StructuredBuffer<ControlPoint> g_ControlPoints		: register (t0);

VertexBufferOutput main( 
	in VertexBufferInput In, 
	in uint uVertexId								: SV_VertexId 
	)
{
	//
	//printf( "Vertex shader call" );
	//
	//printf( "World: %f %f %f %f", g_f4x4World[0][0], g_f4x4World[0][1], g_f4x4World[0][2], g_f4x4World[0][3]);
	//printf( "       %f %f %f %f", g_f4x4World[1][0], g_f4x4World[1][1], g_f4x4World[1][2], g_f4x4World[1][3]);
	//printf( "       %f %f %f %f", g_f4x4World[2][0], g_f4x4World[2][1], g_f4x4World[2][2], g_f4x4World[2][3]);
	//printf( "       %f %f %f %f", g_f4x4World[3][0], g_f4x4World[3][1], g_f4x4World[3][2], g_f4x4World[3][3]);
	//
	//printf( "View : %f %f %f %f", g_f4x4View[0][0], g_f4x4View[0][1], g_f4x4View[0][2], g_f4x4View[0][3]);
	//printf( "       %f %f %f %f", g_f4x4View[1][0], g_f4x4View[1][1], g_f4x4View[1][2], g_f4x4View[1][3]);
	//printf( "       %f %f %f %f", g_f4x4View[2][0], g_f4x4View[2][1], g_f4x4View[2][2], g_f4x4View[2][3]);
	//printf( "       %f %f %f %f", g_f4x4View[3][0], g_f4x4View[3][1], g_f4x4View[3][2], g_f4x4View[3][3]);
	//
	//printf( "Proj : %f %f %f %f", g_f4x4Proj[0][0], g_f4x4Proj[0][1], g_f4x4Proj[0][2], g_f4x4Proj[0][3]);
	//printf( "       %f %f %f %f", g_f4x4Proj[1][0], g_f4x4Proj[1][1], g_f4x4Proj[1][2], g_f4x4Proj[1][3]);
	//printf( "       %f %f %f %f", g_f4x4Proj[2][0], g_f4x4Proj[2][1], g_f4x4Proj[2][2], g_f4x4Proj[2][3]);
	//printf( "       %f %f %f %f", g_f4x4Proj[3][0], g_f4x4Proj[3][1], g_f4x4Proj[3][2], g_f4x4Proj[3][3]);
	//

	VertexBufferOutput Out;

	Out.f2Tex = In.f2Tex;
	Out.f4Normal = In.f4Normal;
	Out.f4Position = g_ControlPoints[In.uControlPoint].f4ControlPoint;
	Out.f4Position.w = 1.0f;

	float4 f4WorldPosition = Out.f4Position = mul(Out.f4Position, g_f4x4World);
	Out.f4Position = mul(Out.f4Position, g_f4x4View);
	Out.f4Position = mul(Out.f4Position, g_f4x4Proj);

	Out.f4Normal = mul(Out.f4Normal, g_f4x4World);
	Out.f4Normal = normalize(Out.f4Normal);

	Out.f4ViewDirection = g_f4CameraPositionWorld - f4WorldPosition;
	Out.f4ViewDirection = mul(Out.f4ViewDirection, g_f4x4World);
	Out.f4ViewDirection = normalize(Out.f4ViewDirection);

	Out.f4LightDirection = -float4(150.0f, 10.0f, -15.0f, 1.0f);
	Out.f4LightDirection = mul(Out.f4LightDirection, g_f4x4World);
	Out.f4LightDirection = normalize(Out.f4LightDirection);

	return Out;
}